home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / share / gufw / model / Firewall.py < prev    next >
Encoding:
Python Source  |  2009-10-25  |  5.7 KB  |  180 lines

  1. # Gufw 9.10.4 - http://gufw.tuxfamily.org
  2. # Copyright (C) 2009 Marcos Alvarez Costales
  3. #
  4. # Gufw is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. # Gufw is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with Gufw; if not, see http://www.gnu.org/licenses for more
  14. # information.
  15.  
  16.  
  17. from FrontEnd import Frontend
  18. from Log      import Log
  19. from Variable import Variable
  20.  
  21.  
  22. class Firewall:
  23.  
  24.     def __init__(self):
  25.     
  26.         self.rules_list = []
  27.         
  28.         self.frontend = Frontend()
  29.         self.log      = Log()
  30.         self.variable = Variable()
  31.         
  32.         self.status    = self.frontend.get_status()
  33.         self.default   = self.frontend.get_default()
  34.         self.ufw_log   = self.frontend.get_ufw_log()
  35.         self.gufw_log  = self.frontend.get_gufw_log()
  36.         self.wrap      = self.log.get_wrapping()
  37.         self.maximized = False
  38.  
  39.  
  40.     # Return status ufw
  41.     def set_status(self, status):
  42.         self.status = self.frontend.set_status(status)
  43.         self.log.add_log(self.gufw_log, self.variable.get_command(status))
  44.         
  45.  
  46.     # Get status ufw
  47.     def get_status(self):
  48.         return self.status
  49.  
  50.  
  51.     # Return status ufw
  52.     def set_default(self, default):
  53.         self.default = self.frontend.set_default(default)
  54.         self.log.add_log(self.gufw_log, self.variable.get_command(default))
  55.  
  56.  
  57.     # Get status ufw 
  58.     def get_default(self):
  59.         return self.default
  60.         
  61.  
  62.     # Get actual rules split by Action
  63.     def get_rules_list(self):
  64.         self.rules_list = []
  65.         
  66.         rules = self.frontend.get_rules()
  67.         
  68.         for rule in rules:
  69.             self.rules_list.append(self.get_rule_split_by_action(rule))
  70.             
  71.         return self.rules_list
  72.  
  73.  
  74.     # Refresh Log
  75.     def refresh_log(self):
  76.         self.log.refresh_log()
  77.  
  78.  
  79.     # Get Log
  80.     def get_log(self):
  81.         return self.log.get_log()
  82.         
  83.  
  84.     # Get Wrapping
  85.     def get_wrap(self):
  86.         return self.log.get_wrapping()
  87.         
  88.         
  89.     # Set Wrapping
  90.     def set_wrap(self, wrapping):
  91.         self.wrap = self.log.set_wrapping(wrapping)
  92.  
  93.     
  94.     # Get ufw log
  95.     def get_ufw_log(self):
  96.         return self.ufw_log
  97.         
  98.         
  99.     # Set ufw log
  100.     def set_ufw_log(self, status):
  101.         self.ufw_log = self.frontend.set_ufw_log(status)
  102.         self.log.add_log(self.gufw_log, self.variable.get_command(status))
  103.     
  104.     
  105.     # Get Gufw log
  106.     def get_gufw_log(self):
  107.         return self.gufw_log
  108.         
  109.         
  110.     # Set Gufw log
  111.     def set_gufw_log(self, status):
  112.         self.gufw_log = self.frontend.set_gufw_log(status)
  113.         if self.gufw_log == self.variable.get_constant("gufw_log_on"):
  114.             self.log.add_log(self.gufw_log, self.variable.get_text("004"))
  115.         else:
  116.             self.log.add_log("gufw_log_on", self.variable.get_text("005"))
  117.     
  118.      
  119.     # Add rule to ufw
  120.     def add_rule(self, service, action, protocol, fromip, fromport, toip, toport):
  121.         rule = self.frontend.add_rule_component(service, action, protocol, fromip, fromport, toip, toport)
  122.         self.log.add_log(self.gufw_log, rule)
  123.         return self.frontend.add_rule(rule)
  124.         
  125.  
  126.     # Remove rule from ufw
  127.     def remove_rule(self, rule_to, action, rule_from):
  128.         rule = self.frontend.remove_rule_component(rule_to, action, rule_from)
  129.         self.log.add_log(self.gufw_log, rule)
  130.         return self.frontend.remove_rule(rule)
  131.  
  132.  
  133.     # Split rule by action
  134.     def get_rule_split_by_action(self, rule):
  135.  
  136.         return_split_rule = []
  137.         
  138.         # Deny?
  139.         if rule.find(self.variable.get_constant("deny_upper")) != -1:
  140.             split_rule = rule.split(self.variable.get_constant("deny_upper"))
  141.             return_split_rule.append(split_rule[0].strip())
  142.             return_split_rule.append(self.variable.get_constant("deny_upper"))
  143.             return_split_rule.append(split_rule[1].strip())
  144.  
  145.         # Allow?
  146.         elif rule.find(self.variable.get_constant("allow_upper")) != -1:
  147.             split_rule = rule.split(self.variable.get_constant("allow_upper"))
  148.             return_split_rule.append(split_rule[0].strip())
  149.             return_split_rule.append(self.variable.get_constant("allow_upper"))
  150.             return_split_rule.append(split_rule[1].strip())
  151.             
  152.         # Limit?
  153.         elif rule.find(self.variable.get_constant("limit_upper")) != -1:
  154.             split_rule = rule.split(self.variable.get_constant("limit_upper"))
  155.             return_split_rule.append(split_rule[0].strip())
  156.             return_split_rule.append(self.variable.get_constant("limit_upper"))
  157.             return_split_rule.append(split_rule[1].strip())
  158.             
  159.         # Reject?
  160.         elif rule.find(self.variable.get_constant("reject_upper")) != -1:
  161.             split_rule = rule.split(self.variable.get_constant("reject_upper"))
  162.             return_split_rule.append(split_rule[0].strip())
  163.             return_split_rule.append(self.variable.get_constant("reject_upper"))
  164.             return_split_rule.append(split_rule[1].strip())
  165.             
  166.         return return_split_rule
  167.  
  168.  
  169.     # Size Gufw window
  170.     def get_old_size_window(self):
  171.         width,height = self.frontend.get_old_size_window()
  172.         return width,height
  173.         
  174.         
  175.     # Save actual size window
  176.     def save_size_window(self, win_width, win_height):
  177.         self.frontend.save_size_window(win_width, win_height)
  178.